package edu.sctu.wujiayi.month06.day20150625.json_test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by user11 on 2015/6/25.
 */
public class JsonUtill {

    public JsonAppbean jsonString(String json){

        JsonAppbean jsonAppbean = new JsonAppbean();
        JSONObject jsonObject = JSON.parseObject(json);
        jsonAppbean.error = jsonObject.getIntValue("error");
        jsonAppbean.message = jsonObject.getString("message");
        jsonAppbean.count = jsonObject.getString("count");
        String list = jsonObject.getString("list");
        JSONArray jsonArray = JSON.parseArray(list);

        for (int i = 0;i < jsonArray.size();i++){

            ListAppbean listAppbean = new ListAppbean();

            listAppbean.rec_id = jsonArray.getJSONObject(i).getString("rec_id");
            listAppbean.goods_id = jsonArray.getJSONObject(i).getString("goods_id");
            listAppbean.category_id = jsonArray.getJSONObject(i).getString("category_id");
            listAppbean.brand_id = jsonArray.getJSONObject(i).getString("brand_id");
            listAppbean.goods_price = jsonArray.getJSONObject(i).getString("goods_price");
            listAppbean.goods_type = jsonArray.getJSONObject(i).getString("goods_type");
            listAppbean.goods_introduce = jsonArray.getJSONObject(i).getString("goods_introduce");

            jsonAppbean.list.add(listAppbean);
        }

    return jsonAppbean;
    }
}
